package com.wang.xh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.xh.user.mapper.UserMapper;
import com.wang.xh.user.domain.User;
import com.wang.xh.user.domain.dto.MemberDTO;
import com.wang.xh.user.service.UserService;
import org.springframework.stereotype.Service;

/**
 * 用户表(User)表服务实现类
 *
 * @author makejava
 * @since 2024-09-08 15:26:25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public MemberDTO detailByOpenId(String openid) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getOpenId, openid);
        User user = this.getOne(queryWrapper);
        if (user != null) {
            return MemberDTO.builder()
                    .id(user.getId())
                    .openId(user.getOpenId())
                    .name(user.getName())
                    .phone(user.getPhone())
                    .sex(user.getSex())
                    .idNumber(user.getIdNumber())
                    .avatar(user.getAvatar())
                    .birthday(user.getBirthday())
                    .createTime(user.getCreateTime())
                    .build();
        }
        return null;
    }
}

